# json： 在数据中带上子字段名和字段的类型
json_str = """
{"id":1500100001,"name":"施笑槐","age":23,"sex":"男"}
"""

# 在python中解析json格式的字符串

import json

# loads:将一个json字符串转换成python对象，字典或者列表
# json工具会自动将json字符串转换成python的对象
obj = json.loads(json_str)

print(obj, type(obj))
# 通过key获取value
print(obj["name"])

json_strs = """
[
{"id":1500100001,"name":"施笑槐","age":23,"sex":"男"},
{"id":1500100001,"name":"施笑槐","age":23,"sex":"男"}
]
"""

objs = json.loads(json_strs)

print(objs, type(objs))

# 定义一个python对象
students = [
    {"id": 1500100001, "name": "施笑槐", "age": 23, "sex": "男"},
    {"id": 1500100001, "name": "施笑槐", "age": 23, "sex": "男"}
]

# dumps: 将python对象转换成json字符串
json_str = json.dumps(students)
print(json_str)